import React, { Component } from "react";

export default class Header extends Component {
  handleKeyDown = (event) => {
    if (event.key === "Enter") {
      const inputValue = event.target.value;
      if (inputValue.trim()) {
        this.props.addItem(inputValue);
        event.target.value = ""; // 清空输入框
      }
    }
  };
  render() {
    return (
      <div className="todo-header">
        <input
          type="text"
          placeholder="请输入你的任务名称，按回车键确认"
          onKeyDown={this.handleKeyDown}
        />
      </div>
    );
  }
}
